package com.rjxy.plansystemmanagement.controller.entityController;

import com.rjxy.plansystemmanagement.entity.FlightInformation;
import com.rjxy.plansystemmanagement.entity.OrderInformation;
import com.rjxy.plansystemmanagement.entity.Result.Result;
import com.rjxy.plansystemmanagement.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/Orders")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 获取所有订单
     * @return
     */
    @GetMapping
    public Result list(){
        log.info("获取所有订单");
        List<OrderInformation> orderInformationList = orderService.list();
        return Result.success(orderInformationList);
    }
    /**
     * 根据id删除指定订单
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result deleteOrder(@PathVariable Integer id){
        log.info("根据id{}删除指定订单",id);
        orderService.deleteOrder(id);
        return Result.success();
    }

    /**
     * 增加订单信息
     * @param orderInformation
     * @return
     */
    @PostMapping
    public Result addOrder(@RequestBody OrderInformation orderInformation){
        log.info("增加订单");
        orderService.addOrder(orderInformation);
        return Result.success();
    }

    /**
     * 查询指定id{}的订单
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result getOrderById(@PathVariable Integer id){
        log.info("查询指定id{}的订单",id);
        OrderInformation orderInformation = orderService.getOrderById(id);
        return Result.success(orderInformation);
    }

    /**
     * 查询指定用户id{}的订单
     * @param id
     * @return
     */
    @GetMapping("/getOrderByUid/{id}")
    public Result getOrderByUid(@PathVariable Integer id){
        log.info("查询指定用户id{}的订单",id);
        List<OrderInformation> userOrderList = orderService.getOrderByUid(id);
        return Result.success(userOrderList);
    }

    @PutMapping
    public Result updateOrder(@RequestBody OrderInformation orderInformation){
        log.info("更新指定订单id{}的订单",orderInformation.getID());
        orderService.updateOrder(orderInformation);
        return Result.success();
    }

}
